package com.explore.demo.controller;


import com.explore.demo.common.ServerResponse;
import com.explore.demo.pojo.Department;
import com.explore.demo.service.DepartmentService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gaolainan
 * @since 2021-04-18
 */
@RestController
@RequestMapping("/department")
public class DepartmentController {

    @Resource
    private DepartmentService departmentService;

    @GetMapping
    @ApiOperation("查询全部部门的信息")
    public ServerResponse query(){
        return departmentService.queryAll();
    }

    @PostMapping
    @ApiOperation("创建一个部门的信息")
    public ServerResponse addOne(Department department){
        return departmentService.addDepartment(department);
    }

    @DeleteMapping
    @ApiOperation("通过部门的名称 删除部门的相关信息")
    public ServerResponse deleteByName(String departmentName){
        return departmentService.deleteByDepartmentName(departmentName);
    }

    @PostMapping("/{departmentName}")
    @ApiOperation("通过部门的名称 查询部门的相关信息")
    public ServerResponse queryByName(@PathVariable("departmentName") String departmentName){
        return departmentService.queryByDepartmentName(departmentName);
    }
}

